﻿/**
 * Created by Administrator on 2017/9/7.
 *公客转私客
 */
define(['jquery','api'],function ($,api) {
    var AbandonCustomer = {
        name: 'abandon-customer',
        template: ''
        + '<Modal title="转为个人客户"'
        + '       v-model="showAbandonCustomer"'
        + '       width="360"'
        + '       ok-text="确认"'
        + '       v-on:on-cancel="closeShift"'
        + '       v-on:on-ok="abandonCustomer"'
        + '       v-bind:loading="true"'
        + '       v-bind:closable="false"'
        + '       v-bind:mask-closable="false"'
        + '       class-name="discardClientWrap  vertical-center-modal abandon-customer"  ref="modal">'
        + '<div class="modal-content">'
        + '    <ul class="pri-ul">'
        + '        <li class="pri-li-txta">'
        + '            <span class="model-left" style="width:130px;">废弃原因</span>'
        + '            <p class="model-right">'
        + '                <textarea name=""  v-model="abandonInfo.remark"></textarea>'
        + '            </p>'
        + '        </li>'
        + '        <li class="pri-li">'
        + '            <span class="model-left removeLeft">清空回访记录</span>'
        + '            <p class="model-right remove-right">'
        + '                <Radio-group v-model="abandonInfo.isClearVisit">'
        + '                    <Radio label="true"><span>是</span></Radio>'
        + '                    <Radio label="false"><span>否</span></Radio>'
        + '                </Radio-group>'
        + '            </p>'
        + '        </li>'
        + '        <h3 class="warning">确认将选中客户废弃吗？</h3>'
        + '    </ul>'
        + '</div>'
        + '</Modal>',
        props: {
            type: String,
            status: String
        },
        data: function () {
            return {
                abandonInfo: {
                    remark: "",
                    isClearVisit: "false",
                    customerIdList: [],
                },
                showAbandonCustomer: false,
            }
        },
        methods: {
            closeShift: function () {
            },
            abandonCustomer() {
                var thisAbandon = this;
                if ($.trim(thisAbandon.abandonInfo.remark) === "") {
                    thisAbandon.$Message.error('丢弃原因不能为空');
                    thisAbandon.$refs.modal.buttonLoading = false;
                    return;
                }
                api.Post_Abandon_Customer(thisAbandon.abandonInfo)
                    .done(function (data) {
                        if (data.IsSuccess) {
                            thisAbandon.$Message.success('丢弃成功');
                            //触发abandonCustomerSuccess
                            window.bus.$emit("abandonCustomerSuccess");
                            thisAbandon.showAbandonCustomer = false;
                        } else {
                            thisAbandon.$Message.error(data.ErrMsg);
                            thisAbandon.$refs.modal.buttonLoading = false;
                        }
                    })
                    .fail(function () {
                        thisAbandon.$Message.error('丢弃失败');
                        thisAbandon.$refs.modal.buttonLoading = false;
                    })
            },
        },
        mounted: function () {
            var thisAbandon = this;
            //监听showAbandonCustomer
            window.bus.$on("showAbandonCustomer", function (data) {
                thisAbandon.abandonInfo.customerIdList = data;
                thisAbandon.showAbandonCustomer = true;
                //触发deleteFocus
                window.bus.$emit("deleteFocus");
            });
        },
    };
    return AbandonCustomer;
});
